import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class SyncExample {

    public static void doSomethingA() {

        try {
            Thread.sleep(4000);

            System.out.println("----doSomethingA----");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void doSomethingB() {
        try {
            Thread.sleep(2000);
            System.out.println("----doSomeThingB----");

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private final static int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();
    private final static ThreadPoolExecutor POOL_EXECUTOR = new ThreadPoolExecutor(AVAILABLE_PROCESSORS,
            AVAILABLE_PROCESSORS * 2, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(5));

    public static void main(String[] args) {

        long start = System.currentTimeMillis();
        //doSomethingA();
        POOL_EXECUTOR.execute(SyncExample::doSomethingA);
        POOL_EXECUTOR.execute(SyncExample::doSomethingB);
        System.out.println("????");
        System.out.println(System.currentTimeMillis() - start);
    }
}
